package io.alvin.ch05;

/**
 * 单例模式，懒加载
 * 静态内部类，是在被调用时加载。即getInstance方法被第一次调用时，StaticSingleton的实例被创建。
 *
 * Created by Alvin on 2017/7/13.
 */
public class StaticSingleton {

    private StaticSingleton() {
        System.out.println("StaticSingleton is created");
    }

    private static class SingletonHolder {
        private static StaticSingleton instance = new StaticSingleton();
    }

    public static StaticSingleton getInstance() {
        return SingletonHolder.instance;
    }
}
